<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="back" @click="navigateBack">
        <uni-icons type="left" size="20" color="#fff"></uni-icons>
      </view>
      <view class="title">维修记录</view>
      <view class="right">
        <uni-icons type="more-filled" size="20" color="#fff"></uni-icons>
      </view>
    </view>
    
    <!-- 核销码区域 -->
    <view class="bg">
		
	</view>
    <view class="qrcode-section" v-if="repairStatus !== '已取消'">
      <view class="code-text">核销码：WE343235V</view>
      <image class="qrcode" src="/static/qrcode.png" mode="aspectFit"></image>
    </view>
    
    <!-- 维修信息 -->
    <view class="info-section">
      <view class="section-title">维修信息</view>
      <view class="info-list">
        <view class="info-item">
          <text class="label">维修单号：</text>
          <text class="value">3535252</text>
        </view>
        <view class="info-item">
          <text class="label">维修状态：</text>
          <text class="value" :class="{'canceled': repairStatus === '已取消'}">
            {{ repairStatus }}
          </text>
        </view>
        <view class="info-item">
          <text class="label">车主姓名：</text>
          <text class="value">张</text>
        </view>
        <view class="info-item">
          <text class="label">联系方式：</text>
          <text class="value">1993829282</text>
        </view>
        <view class="info-item">
          <text class="label">维修方式：</text>
          <text class="value">上门取车</text>
        </view>
        <view class="info-item">
          <text class="label">取车位置：</text>
          <text class="value">山阳区32号</text>
        </view>
        <view class="info-item">
          <text class="label">预约日期：</text>
          <text class="value">2022/11/10 11:00</text>
        </view>
        <view class="info-item">
          <text class="label">提交日期：</text>
          <text class="value">2022/11/08 12:34</text>
        </view>
      </view>
    </view>
    
    <!-- 车辆信息 -->
    <view class="info-section">
      <view class="section-title">车辆信息</view>
      <view class="info-list">
        <view class="info-item">
          <text class="label">车辆类型：</text>
          <text class="value">大客车</text>
        </view>
        <view class="info-item">
          <text class="label">车牌号：</text>
          <text class="value">豫J45323</text>
        </view>
        <view class="info-item">
          <text class="label">整车照片：</text>
        </view>
        <view class="image-preview">
          <image src="/static/car.jpg" mode="aspectFill"></image>
        </view>
        <view class="info-item">
          <text class="label">维修部位照片：</text>
        </view>
        <view class="image-preview multi">
          <image v-for="(img, index) in repairImages" 
                 :key="index" 
                 :src="img" 
                 mode="aspectFill"
                 @click="previewImage(img)"></image>
        </view>
      </view>
    </view>

    <!-- 取消订单按钮 -->
    <view class="bottom-btn" v-if="repairStatus === '进行中'">
      <button class="cancel-btn" @click="showCancelConfirm">取消订单</button>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'

onLoad((options)=>{
	console.log(options)
})
// 定义响应式数据
const repairStatus = ref('进行中');
const repairImages = ref([
  '/static/car.jpg',
  '/static/car.jpg',
  '/static/car.jpg'
]);

// 定义方法
const navigateBack = () => {
  uni.navigateBack();
};

const previewImage = (current) => {
  uni.previewImage({
    urls: repairImages.value,
    current
  });
};

const showCancelConfirm = () => {
  uni.showModal({
    title: '提示',
    content: '确认要取消该维修订单吗？',
    success: (res) => {
      if (res.confirm) {
        cancelOrder();
      }
    }
  });
};

const cancelOrder = () => {
  // 这里可以添加调用取消订单API的逻辑
  repairStatus.value = '已取消';
  uni.showToast({
    title: '订单已取消',
    icon: 'success'
  });
};
</script>

<style lang="scss" scoped>
	.bg{
		width: 100%;
		height: 250rpx;
		background-color: #007aff;
	}
.container {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding-bottom: 100px; // 为底部按钮留出空间
}

.nav-bar {
  display: flex;
  align-items: center;
  height: 44px;
  background-color: #007AFF;
  color: #fff;
  padding: 0 15px;
  
  .back {
    width: 44px;
  }
  
  .title {
    flex: 1;
    text-align: center;
    font-size: 18px;
  }
  
  .right {
    width: 44px;
    text-align: right;
  }
}

.qrcode-section {
	margin-left: 10px;
	margin-right: 10px;
	margin-top: -200rpx;
	border-top-right-radius: 20px;
	border-top-left-radius: 20px;
  background-color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 10px;
  
  .code-text {
    color: #666;
    font-size: 14px;
    margin-bottom: 15px;
  }
  
  .qrcode {
    width: 200px;
    height: 200px;
  }
}

.info-section {
	margin-left: 10px;
	margin-right: 10px;	
  background-color: #fff;
  margin-bottom: 10px;
  padding: 15px;
  
  .section-title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
    position: relative;
    padding-left: 10px;
    
    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 3px;
      height: 16px;
      background-color: #007AFF;
    }
  }
  
  .info-list {
    .info-item {
      display: flex;
      margin-bottom: 12px;
      font-size: 14px;
      
      .label {
        width: 90px;
        color: #666;
      }
      
      .value {
        flex: 1;
        color: #333;
        
        &.canceled {
          color: #ff4d4f;
        }
      }
    }
  }
}

.image-preview {
  padding: 0 0 12px 90px;
  
  image {
    width: 200px;
    height: 120px;
    border-radius: 4px;
  }
  
  &.multi {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    
    image {
      width: 100px;
      height: 100px;
    }
  }
}

.bottom-btn {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background-color: #fff;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  
  .cancel-btn {
    width: 100%;
    height: 44px;
    line-height: 44px;
    background-color: #007AFF;
    color: #fff;
    border-radius: 22px;
    font-size: 16px;
    
    &:active {
      opacity: 0.8;
    }
  }
}
</style>